The Beginner's Guide to Markdown and Pandoc by Thomas Mailund

The Beginner's Guide to Markdown and Pandoc by Thomas Mailund

Author:Thomas Mailund [Mailund, Thomas]
Language: eng
Format: epub
Published: 2017-03-30T07:00:00+00:00


Using Make-files

For this book, I have all my text in a single book.md document. This is fine for a very short book like this one, but usually, I keep each chapter in a separate file. The command line for compiling my books can get rather long, and I usually have various options for different output formats that I need to remember, so if I had to use the command line each time I wanted to build a new version of a book, it would quickly become tedious and extremely error-prone. So I use Make for compiling my books. If you are not familiar with Make, you might want to skip this section. It is beyond the scope of this book to explain Make, but for those familiar with Make I will give an example of how I use it together with Pandoc.

The Makefile I use for this book looks roughly like this (although I have left out options that I have not explained yet in this book):

SOURCE_CHAPTERS := header.yml book.md PANDOC := pandoc PANDOC_OPTS_ALL := --toc --smart \ --top-level-division=chapter PANDOC_PDF_OPTS := $(PANDOC_OPTS_ALL) \ --default-image-extension=pdf \ --metadata documentclass=scrbook \ --metadata geometry=b5paper PANDOC_EPUB_OPTS := $(PANDOC_OPTS_ALL) \ --default-image-extension=png \ -t epub3 --toc-depth=1 \ --epub-cover-image=cover.png all: book.pdf book.epub book.mobi book.pdf: $(SOURCE_CHAPTERS) Makefile $(PANDOC) $(PANDOC_PDF_OPTS) -o $@ $(SOURCE_CHAPTERS) book.epub: $(SOURCE_CHAPTERS) Makefile $(PANDOC) $(PANDOC_EPUB_OPTS) -o $@ $(SOURCE_CHAPTERS) book.mobi: book.epub ./kindlegen book.epub -o book.mobi clean: rm book.pdf book.epub book.mobi

I use a variable to hold the input files. Just the header and the single Markdown file in this case, but this is usually a longer list. Especially when I write about R programming, where I need to preprocess all input files, which can be a slow process, and I do that chapter wise, so I don’t have to redo the preprocessing unless a chapter has changed.

I keep the Pandoc command tool in a variable as well. I have more than one version installed, and I can switch between them by changing the variable.

I then define some options I want to use for all output formats and then options that I only want to use for PDF and others I only want to use for ebooks. The metadata I set for PDF output I could also have put in the header—they wouldn’t interfere with the EPUB output if I did—but I have chosen to set them here.

I then define three targets for when I call make without arguments, a PDF book, an EPUB book, and a Kindle book (file format MOBI). I use Pandoc to build the PDF and EPUB version, but Pandoc cannot create MOBI files directly, so I use the KindleGen tool for that.

For this book, I don’t plan to use the PDF version for anything. I just prefer viewing the formatting in PDF because it is less cumbersome to see new changes in my PDF view than my ebook viewer. I am only planning to make this book into a Kindle ebook, so the real target is book.mobi.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.